<template>
	<view class="page-body">
		<!-- 页面内容开始 -->
		<view style="padding: 20rpx;margin: 24px 15px; background-color: #fad1c8;border-radius: 10rpx;">
			<view style="margin-top: 7px;">
				<el-link :underline="false" icon="el-icon-bell">抖音媒资管理使用</el-link>


			</view>
			<view style="margin-top: 7px;">
				<view class="">
					1.在没有报错的情况下，不要重复点击【更多】中的按钮
					<br />
					2.【添加】短剧信息时，第一次填写正确，不支持再次修改
					<br />
					3.【一键上传视频】，在 请求中 的情况下，不要关闭浏览器，等待上传完成即可
					<br />
					4.【一键填充vid】，抖音云视频标题必须含有完整短剧标题，并以 第1集.mp4结尾 不要使用01.02表示，推荐 西游记-第1集.mp4 等等

				</view>
			</view>

		</view>

		<!-- 表格搜索组件开始 -->
		<vk-data-table-query v-model="queryForm1.formData" :columns="queryForm1.columns" @search="search">
		</vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<!-- 自定义按钮区域开始 -->
		<view v-if="vk.vuex.get('$user.userInfo.username')=='admin'">
			<el-row>
				<el-button type="success" size="small" icon="el-icon-circle-plus-outline" @click="addBtn">添加</el-button>


			</el-row>
		</view>
		<!-- 自定义按钮区域结束 -->

		<view v-if="vk.vuex.get('$user.userInfo.username')=='admin'">
			<!-- 表格组件开始 -->
			<!-- <vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['detail_auto','update','delete','more']" :right-btns-more="table1.rightBtnsMore"
				:selection="true" :row-no="true" :pagination="true" @update="updateBtn" @delete="deleteBtn"
				@current-change="currentChange" @selection-change="selectionChange">
			</vk-data-table> -->
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['detail_auto','update','delete','more']" :right-btns-more="table1.rightBtnsMore"
				:selection="false" :row-no="true" :pagination="true" :border="true" :stripe="true" @delete="deleteBtn"
				@current-change="currentChange" @update="updateBtn" @selection-change="selectionChange">
			</vk-data-table>
			<!-- 表格组件结束 -->
		</view>

		<view v-else>
			<!-- 表格组件开始 -->
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['more']" :right-btns-more="table1.rightBtnsMore" :selection="false" :row-no="true"
				:pagination="true" @current-change="currentChange" @selection-change="selectionChange">
			</vk-data-table>
			<!-- 表格组件结束 -->
		</view>


		<!-- 添加或编辑的弹窗开始 -->
		<vk-data-dialog v-model="form1.props.show" :title="form1.props.title" width="900px" mode="form"
			:close-on-click-modal="false">
			<vk-data-form v-model="form1.data" :rules="form1.props.rules" :action="form1.props.action"
				:form-type="form1.props.formType" :columns='form1.props.columns' label-width="140px"
				@success="form1.props.show = false;refresh();">

				<template v-slot:footer="{ loading }">
					<view style="text-align: center;">
						<el-button :loading="loading" type="danger" style="padding: 10px 40px;margin-right: 30px; "
							@click="form1.props.show=false"> 取消 </el-button>
						<el-button :loading="loading" type="success" style="padding: 10px 40px; "
							@click="batchAdd(form1.data)"> 确定
						</el-button>
					</view>
				</template>

			</vk-data-form>
		</vk-data-dialog>
		<!-- 添加或编辑的弹窗结束 -->

		<!-- 弹窗预览分集数据开始 -->
		<el-dialog title="分集数据预览" :visible.sync="dialogVisible" width="70%" :before-close="handleClose"
			:destroy-on-close="true" :center="true" :close-on-click-modal="false">
			<el-row>
				<el-col :span="12">
					<text style="font-size: large;margin-left: 10rpx;">当前播放:第{{currentserie}}集</text>
					<scroll-view scroll-y="true" style="height: 1250rpx;" :show-scrollbar="true">
						<block v-for="(item,index) in temp_series_list" :key="index">
							<el-button type="primary" @click="cut_serie(item)"
								style="width:170rpx;margin-bottom: 10rpx;margin-left: 10rpx;">第{{item.series}}集
							</el-button>
						</block>
					</scroll-view>

				</el-col>
				<el-col :span="10">
					<view style="align-content: center;margin-left: 30rpx;">
						<video v-if="dialogVisible" id="myVideo" :src="currentlink" controls
							style="width: 700rpx;height: 1300rpx;" :autoplay="true"></video>
					</view>
				</el-col>
			</el-row>

			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">关 闭</el-button>
				<el-button type="primary" @click="copylink">复制视频链接并下载</el-button>
			</span>
		</el-dialog>
		<!-- 弹窗预览分集数据结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	var originalForms = {}; // 表单初始化数据
	const db = uniCloud.database();
	export default {
		data() {
			// 页面数据变量
			return {
				store: {},
				baseurl: "",
				tips: "请勿关闭浏览器...",
				currentserie: 1,
				currentlink: "", //当前播放视频链接
				temp_series_list: [],
				dialogVisible: false, //控制弹窗是否开启
				// 页面是否请求中或加载中
				loading: false,
				// init请求返回的数据
				data: {

				},
				// 表格相关开始 -----------------------------------------------------------
				table1: {
					rightBtnsMore: [{
							title: '创建短剧',
							disabled: (item) => {
								if (item.status) {
									return true;
								} else {
									return false;
								}
							},
							async onClick(item) {
								if (!item.album_info.record_audit_info.broadcast_record_info
									.broadcast_record_number) {
									delete item.album_info.record_audit_info.broadcast_record_info
								}
								console.log("item==========", item);
								console.log("_id", item._id);
								console.log("ma_app_id", item.ma_app_id);
								console.log("album_info", item.album_info);
								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv/kh/createTvRequest',
									title: '请求中...',
									data: {
										_id: item._id,
										ma_app_id: item.ma_app_id,
										album_info: item.album_info,
										// record_info:item.record_info
									},
									success: (data) => {
										vk.alert('操作成功');
										this.refresh()
									},

								});
								this.refresh()
							}
						},
						{
							title: '一键上传视频',
							disabled: (item) => {
								// if (item.audit_status == 3) {
								// 	return false;
								// } else {
								// 	// 未创建
								// 	return true;
								// }

							},
							onClick: (item) => {
								console.log("item===", item);


								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv_series/kh/uploadVideos',
									title: '请求中...',
									data: {
										_id: item._id,
										ma_app_id: item.ma_app_id,
										album_id: item.album_id
									},
									success: (data) => {
										this.refresh()
									}
								});

							}

						},
						{
							title: '短剧编辑',
							disabled: (item) => {
								// if (item.status) {
								// 	// if (item.audit_status == 2 || item.audit_status == 3) {
								// 	// 	console.log("222222");
								// 	// 	return true
								// 	// }
								// 	return false;
								// } else {
								// 	console.log("33333333");
								// 	return true;
								// }
							},
							onClick: (item) => {
								//判断是否有广电备案
								if (item.album_info.record_audit_info.broadcast_record_info) {
									if (!item.album_info.record_audit_info.broadcast_record_info
										.broadcast_record_number) {
										delete item.album_info.record_audit_info.broadcast_record_info
									}

								}
								console.log('看看处理后的数据', item);
								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv/kh/updataVideo',
									title: '请求中...',
									data: {
										_id: item._id,
										ma_app_id: item.ma_app_id,
										album_id: item.album_id,
										album_info: item.album_info,

									},
									success: (data) => {
										vk.alert('操作成功');
										this.refresh()
									}
								});
							}
						},

						{
							title: '短剧送审',
							disabled: (item) => {
								// if (item.status) {
								// 	// if (item.audit_status == 2 || item.audit_status == 3) {
								// 	// 	console.log("222222");
								// 	// 	return true
								// 	// }
								// 	return false;
								// } else {
								// 	console.log("33333333");
								// 	return true;
								// }
							},
							onClick: (item) => {
								console.log("item===", item);
								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv/kh/updataVideo',
									title: '请求中...',
									data: {
										_id: item._id,
										ma_app_id: item.ma_app_id,
										album_id: item.album_id,
										album_info: item.album_info,
										djbj: "djbj"
									},
									success: (data) => {
										vk.alert('操作成功');
										this.refresh()
									}
								});
							}
						},

						{
							title: '短剧上线',
							disabled: (item) => {
								if (item.audit_status == 3) {
									return false;
								} else {
									// 未创建
									return true;
								}
							},
							onClick: (item) => {
								console.log("item===", item);

								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv/kh/onlinedj',
									title: '请求中...',
									data: {
										ma_app_id: item.ma_app_id,
										album_id: item.album_id,
									},
									success: (data) => {
										this.refresh()
									}
								});
								this.refresh()
							}
						},
						{
							title: '审核查询',
							disabled: (item) => {


							},
							onClick: (item) => {
								console.log("item===", item);

								vk.callFunction({
									url: 'admin/pages/pub/queryStatus',
									title: '请求中...',
									data: {
										appid: item.ma_app_id,
										album_id: item.album_id,
									},
									success: (data) => {
										// console.log("data",data);
										this.refresh()
									}
								});

							}
						},
						{
							title: '后置审核查询',
							disabled: (item) => {
								return !item.online_status

							},
							onClick: (item) => {
								console.log("item===", item);

								vk.callFunction({
									url: 'admin/pages/pub/queryStatus',
									title: '请求中...',
									data: {
										appid: item.ma_app_id,
										album_id: item.album_id,
										post_review: true
									},
									success: (data) => {
										this.refresh()
									}
								});

							}
						},
						{
							title: '一键填充vid',
							disabled: (item) => {
								if (item.audit_status == 1) {
									return false;
								} else {
									// 未创建
									return true;
								}
								console.log("disableditem===", item);

							},
							onClick: (item) => {
								console.log("onClickitem===", item);

								vk.callFunction({
									url: 'admin/pages/pub/gitList2',
									title: '请求中...',
									data: {
										appid: item.ma_app_id,
										tvName: item.album_info.title,
										total_num: item.album_info.seq_num,
										tv_id: item._id
									},
									success: (data) => {
										console.log("data", data);
									}
								});
								this.refresh()
							}
						},


					],
					// 表格数据请求地址
					action: "admin/pages/files_mzgl/dy_tv/kh/getList",
					// 表格字段显示规则

					columns: [{
							"key": "album_id",
							"title": "短剧ID",
							"type": "number",
						},
						{
							"key": "status",
							"title": "短剧创建状态",
							"type": "tag",
							"data": [{
									value: false,
									label: "未创建",
									tagType: "default"
								},
								{
									value: true,
									label: "已创建",
									tagType: "success"
								}
							]
						},

						{
							"key": "audit_status",
							"title": "短剧审核状态",
							"type": "tag",
							"data": [{
									value: 1,
									label: "未送审",

								},
								{
									value: 2,
									label: "已送审"
								},
								{
									value: 3,
									label: "审核通过",
									tagType: "success"
								},
								{
									value: 4,
									label: "审核未通过",
									tagType: "danger"
								}, {
									value: 5,
									label: "已编辑",
								},

							]
						},

						{
							"key": "online_status",
							"title": "短剧上线状态",
							"type": "tag",
							"data": [{
									value: false,
									label: "未上线",
									tagType: "default"
								},
								{
									value: true,
									label: "已上线",
									tagType: "success"
								}
							]
						},

						{
							"key": "ma_app_id",
							"title": "小程序appid",
							"type": "text"
						},
						{
							key: "album_info",
							title: "短剧信息",
							type: "object",
							width: 300,
							align: "left",
							columns: [{
									"key": "title",
									"title": "短剧标题",
									"type": "text"
								},
								{
									"key": "seq_num",
									"title": "总集数",
									"type": "number",
									"placeholder": "该剧总集数，填写数字即可"
								},

								{
									"key": "cover_list",
									title: "封面图列表",
									type: "text",

								},

								{
									"key": "year",
									"title": "发行年份",
									"type": "number",
									"placeholder": "该剧发行年份，填写数字即可"
								},
								{
									"key": "album_status",
									"title": "短剧更新状态",
									"type": "select",
									"data": [{
											value: 1,
											label: "未上映"
										},
										{
											value: 2,
											label: "更新中"
										},
										{
											value: 3,
											label: "已完结"
										},
									],
								},
								{
									"key": "recommendation",
									"title": "短剧推荐语",
									"type": "text",
									"placeholder": "12个汉字以内"
								},
								{
									"key": "desp",
									"title": "短剧简介",
									"type": "textarea",
									"placeholder": "200个汉字以内",
									"autosize": {
										minRows: 4,
										maxRows: 10
									},
									"maxlength": 200,
									"showWordLimit": true,
								},

								{
									"key": "tag_list",
									"title": "短剧类目标签",
									"type": "select",

									"data": [{
											value: 1,
											label: "医神"
										},
										{
											value: 2,
											label: "赘婿"
										},
										{
											value: 3,
											label: "鉴宝"
										},
										{
											value: 4,
											label: "战神"
										},
										{
											value: 5,
											label: "娱乐明星"
										},
										{
											value: 6,
											label: "神医"
										},
										{
											value: 7,
											label: "重生"
										},
										{
											value: 8,
											label: "职场"
										},
										{
											value: 9,
											label: "逆袭"
										},
										{
											value: 10,
											label: "复仇"
										},
										{
											value: 11,
											label: "青春"
										},
										{
											value: 12,
											label: "官场"
										},
										{
											value: 13,
											label: "家庭情感"
										},
										{
											value: 14,
											label: "乡村"
										},
										{
											value: 15,
											label: "正能量"
										},
										{
											value: 16,
											label: "成长"
										},
										{
											value: 17,
											label: "伦理"
										},
										{
											value: 18,
											label: "都市情感"
										},
										{
											value: 19,
											label: "社会话题"
										},
										{
											value: 20,
											label: "灵异"
										},
										{
											value: 21,
											label: "悬疑推理"
										},
										{
											value: 22,
											label: "虐恋"
										},
										{
											value: 23,
											label: "甜宠"
										},
										{
											value: 24,
											label: "高干军婚"
										},
										{
											value: 25,
											label: "年代"
										},
										{
											value: 26,
											label: "萌宝"
										},
										{
											value: 27,
											label: "腹黑"
										},
										{
											value: 28,
											label: "总裁"
										},
										{
											value: 29,
											label: "宫斗宅斗"
										},
										{
											value: 30,
											label: "穿越"
										},
										{
											value: 31,
											label: "种田经商"
										},
										{
											value: 33,
											label: "民俗"
										},
										{
											value: 34,
											label: "古装"
										},
										{
											value: 35,
											label: "穿越战争"
										},
										{
											value: 36,
											label: "现代军事"
										},
										{
											value: 37,
											label: "奇幻"
										},
										{
											value: 38,
											label: "科幻"
										},
										{
											value: 39,
											label: "架空玄幻"
										},
										{
											value: 40,
											label: "热血"
										},
										{
											value: 41,
											label: "历史"
										},
										{
											value: 42,
											label: "搞笑"
										},
										{
											value: 43,
											label: "仙侠"
										},
										{
											value: 44,
											label: "武侠"
										},
										{
											value: 45,
											label: "二次元"
										},
										{
											value: 46,
											label: "其他"
										}
									],

								},


								{
									"key": "qualification",
									"title": "资质状态",
									"type": "select",
									"data": [{
											value: 1,
											label: "未报审"
										},
										{
											value: 2,
											label: "报审通过"
										},
										{
											value: 3,
											label: "报审不通过"
										},
										{
											value: 4,
											label: "不建议报审"
										},
									],
								},
							],
						},

						{
							"key": "audit_msg",
							"title": "剧审核备注",
							"type": "text",
						},
						{
							"key": "scope_list",
							"title": "剧能力列表",
							"type": "text",
						}, {
							"key": "version",
							"title": "剧审核版本",
							"type": "number",
						},
						{
							"key": "1",
							"title": "↓↓↓后置审核相关↓↓↓",
							"type": "text",
							show: ["detail"]
						},
						{
							key: "",
							title: "后置审核状态",
							type: "group",
							minWidth: 250,
							show: ["row"],
							align: "left",
							columns: [{
									key: "post_review.cover_review.audit_result",
									title: "短剧图片&标题&简介审核",
									type: "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "post_review.path_redirect_review.audit_result",
									title: "path重定向校验",
									type: "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "post_review.path_bind_review.audit_result",
									title: "path绑定校验",
									type: "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								}, {
									key: "post_review.path_quality_review.audit_result",
									title: "path跳转异常校验",
									type: "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
							],
						},
						{
							key: "post_review.cover_review",
							title: "短剧图片&标题&简介审核",
							type: "object",
							minWidth: 100,
							show: ["detail"],
							columns: [{
									key: "audit_result",
									title: "审核状态",
									"type": "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "fail_reason",
									title: "审核失败原因",
									type: "text",
									defaultValue: "无数据"

								},
								{
									key: "tips",
									title: "处理建议",
									type: "text",
									defaultValue: "无数据"

								}
							],
						}, {
							key: "post_review.path_redirect_review",
							title: "path重定向校验",
							type: "object",
							show: ["detail"],
							minWidth: 100,
							columns: [{
									key: "audit_result",
									title: "审核状态",
									"type": "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "fail_reason",
									title: "审核失败原因",
									type: "text",
									defaultValue: "无数据"

								},
								{
									key: "tips",
									title: "处理建议",
									type: "text",
									defaultValue: "无数据"

								}
							],
						}, {
							key: "post_review.path_bind_review",
							title: "path绑定校验",
							type: "object",
							show: ["detail"],
							minWidth: 100,
							columns: [{
									key: "audit_result",
									title: "审核状态",
									"type": "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "fail_reason",
									title: "审核失败原因",
									type: "text",
									defaultValue: "无数据"

								},
								{
									key: "tips",
									title: "处理建议",
									type: "text",
									defaultValue: "无数据"

								}
							],
						}, {
							key: "post_review.path_quality_review",
							title: "path跳转异常校验",
							type: "object",
							show: ["detail"],
							minWidth: 100,
							columns: [{
									key: "audit_result",
									title: "审核状态",
									"type": "tag",
									"data": [{
											value: "PASS",
											label: "审核通过",
											tagType: "success"
										},
										{
											value: "REJECT",
											label: "审核拒绝",
											tagType: "danger"
										}
									]
								},
								{
									key: "fail_reason",
									title: "审核失败原因",
									type: "text",
									defaultValue: "无数据"

								},
								{
									key: "tips",
									title: "处理建议",
									type: "text",
									defaultValue: "无数据"

								}
							],
						},

					],
					// 多选框选中的值
					multipleSelection: [],
					// 当前高亮的记录
					selectItem: ""
				},
				// 表格相关结束 -----------------------------------------------------------
				// 表单相关开始 -----------------------------------------------------------
				// 查询表单请求数据
				queryForm1: {
					// 查询表单数据源，可在此设置默认值
					formData: {

					},
					// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
					columns: [{
							"key": "ma_app_id",
							"title": "小程序appid",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "album_id",
							"title": "短剧ID",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							"key": "album_info.title",
							"title": "短剧标题",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
						{
							key: "audit_status",
							title: "短剧审核状态",
							type: "select",
							data: [{
									value: 1,
									label: "未送审",

								},
								{
									value: 2,
									label: "已送审"
								},
								{
									value: 3,
									label: "审核通过",
									tagType: "success"
								},
								{
									value: 4,
									label: "审核未通过",
									tagType: "danger"
								},
								{
									value: 5,
									label: "已编辑",

								},
							],
							"mode": "="
						},


						{
							key: "online_status",
							title: "短剧上线状态",
							type: "select",
							data: [{
									value: false,
									label: "未上线",

								},
								{
									value: true,
									label: "已上线"
								},

							],
							"mode": "="
						},

					]
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {
						//设置默认值
						album_id: 0, //默认返回的
						record_material: {
							actor: [],
							producer: [],
							director: [],
							screen_writer: []
						},
						qualification: 1
					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "",

						// 表单字段显示规则
						columns: [{
								"key": "ma_app_id",
								title: "小程序id",
								type: "table-select",
								placeholder: "请选择小程序id",
								// multiple: true,
								// valueFields: ["album_id", "album_info.title"],
								"action": "admin/pages/kh/xcxpz/xcxgl/getList",
								"columns": [{
										key: "appid",
										title: "小程序id",
										type: "text",
										idKey: true
									}, {
										key: "appname",
										title: "小程序名称",
										type: "text",
										nameKey: true,
									}

								],
							},

							{
								key: "album_info",
								title: "短剧信息",
								type: "object",
								columns: [{
										"key": "title",
										"title": "短剧标题",
										"type": "text",
										tips: `<text>点此查看命名规范</text><a href="https://www.volcengine.com/docs/4/1200126" target="_blank">命名规范</a>`,
									},
									{
										"key": "seq_num",
										"title": "总集数",
										"type": "number",
										"placeholder": "该剧总集数，填写数字即可"
									},

									{
										"key": "cover_list",
										title: "封面图列表",
										type: "table-select",
										placeholder: "请选择封面",
										queryColumns: [{
												key: "open_pic_id",
												title: "图片id",
												type: "text",
												width: 150,
												mode: "%%"
											},
											{
												key: "display_name",
												title: "名称",
												type: "text",
												width: 150,
												mode: "%%"
											}
										],
										tips: "请选择有封面id的图片",
										"action": "admin/system_uni/uni-id-files/files/kh/getList",
										"columns": [{
												key: "open_pic_id",
												title: "封面id",
												type: "text",
												idKey: true,
												nameKey: true

											},
											{
												key: "url",
												title: "封面",
												type: "image",
											}, {
												key: "display_name",
												title: "名称",
												type: "text",
											},
										],
										multiple: true,
										watch: (res) => {
											if (typeof res.option[0].open_pic_id === "undefined") {
												// 变量的值为 undefined
												vk.alert('该图片没有图片id，请重新选择');
												return
											}
											this.form1.data.album_info.cover_list = vk.pubfn
												.arrayObjectGetArray(res.option, "open_pic_id")
											console.log("watch", res)
											console.log("cover_list:", this.form1.data.album_info.cover_list);
										}
									},
									{
										"key": "year",
										"title": "发行年份",
										"type": "number",
										"placeholder": "该剧发行年份，填写数字即可"
									},
									{
										"key": "album_status",
										"title": "短剧更新状态",
										"type": "select",
										"data": [
											// {
											// 	value: 1,
											// 	label: "未上映"
											// },
											// {
											// 	value: 2,
											// 	label: "更新中"
											// },
											{
												value: 3,
												label: "已完结"
											},
										],
									},
									{
										"key": "recommendation",
										"title": "短剧推荐语",
										"type": "text",
										"placeholder": "12个汉字以内",
										tips: "12个汉字以内"

									},
									{
										"key": "desp",
										"title": "短剧简介",
										"type": "textarea",
										"placeholder": "200个汉字以内",
										"autosize": {
											minRows: 4,
											maxRows: 10
										},
										"maxlength": 200,
										"showWordLimit": true,
										tips: "200个汉字以内"
									},

									{
										"key": "tag_list",
										"title": "短剧类目标签",
										"type": "select",
										"filterable": true,
										"clearable": true,
										"data": [{
												value: 1,
												label: "医神"
											},
											{
												value: 2,
												label: "赘婿"
											},
											{
												value: 3,
												label: "鉴宝"
											},
											{
												value: 4,
												label: "战神"
											},
											{
												value: 5,
												label: "娱乐明星"
											},
											{
												value: 6,
												label: "神医"
											},
											{
												value: 7,
												label: "重生"
											},
											{
												value: 8,
												label: "职场"
											},
											{
												value: 9,
												label: "逆袭"
											},
											{
												value: 10,
												label: "复仇"
											},
											{
												value: 11,
												label: "青春"
											},
											{
												value: 12,
												label: "官场"
											},
											{
												value: 13,
												label: "家庭情感"
											},
											{
												value: 14,
												label: "乡村"
											},
											{
												value: 15,
												label: "正能量"
											},
											{
												value: 16,
												label: "成长"
											},
											{
												value: 17,
												label: "伦理"
											},
											{
												value: 18,
												label: "都市情感"
											},
											{
												value: 19,
												label: "社会话题"
											},
											{
												value: 20,
												label: "灵异"
											},
											{
												value: 21,
												label: "悬疑推理"
											},
											{
												value: 22,
												label: "虐恋"
											},
											{
												value: 23,
												label: "甜宠"
											},
											{
												value: 24,
												label: "高干军婚"
											},
											{
												value: 25,
												label: "年代"
											},
											{
												value: 26,
												label: "萌宝"
											},
											{
												value: 27,
												label: "腹黑"
											},
											{
												value: 28,
												label: "总裁"
											},
											{
												value: 29,
												label: "宫斗宅斗"
											},
											{
												value: 30,
												label: "穿越"
											},
											{
												value: 31,
												label: "种田经商"
											},
											{
												value: 33,
												label: "民俗"
											},
											{
												value: 34,
												label: "古装"
											},
											{
												value: 35,
												label: "穿越战争"
											},
											{
												value: 36,
												label: "现代军事"
											},
											{
												value: 37,
												label: "奇幻"
											},
											{
												value: 38,
												label: "科幻"
											},
											{
												value: 39,
												label: "架空玄幻"
											},
											{
												value: 40,
												label: "热血"
											},
											{
												value: 41,
												label: "历史"
											},
											{
												value: 42,
												label: "搞笑"
											},
											{
												value: 43,
												label: "仙侠"
											},
											{
												value: 44,
												label: "武侠"
											},
											{
												value: 45,
												label: "二次元"
											},
											{
												value: 46,
												label: "其他"
											}
										],
										"placeholder": "1-3个。示例:[1]",
										watch: (res) => {

											this.form1.data.album_info.tag_list = vk.pubfn.arrayObjectGetArray(
												res.option, "value")

											console.log("watch", res)
										},
										multiple: true,
									},
									{
										"key": "qualification",
										"title": "资质状态",
										"type": "select",
										"data": [{
												value: 1,
												label: "未报审"
											},
											{
												value: 2,
												label: "报审通过"
											},
											{
												value: 3,
												label: "报审不通过"
											},
											{
												value: 4,
												label: "不建议报审"
											},
										],


									},
								],

							},
							{
								"key": "",
								"title": "↓↓↓剧目审核备案相关↓↓↓",
								"type": "bar-title"
							},
							{
								key: "record_info",
								title: "备案信息(包含一种备案号即可)",
								type: "object",
								showRule: (formData) => {
									if (formData.album_info.qualification != 1) {
										return true;
									} else {
										this.form1.data.record_info.license_num = ""
										this.form1.data.record_info.registration_num = ""
										this.form1.data.record_info.ordinary_record_num = ""
										this.form1.data.record_info.key_record_num = ""
										return false;
									}
								},
								columns: [{
										key: "license_num",
										title: "许可证号",
										type: "text",

										tips: "未报审时不用填写"
									},
									{
										key: "registration_num",
										title: "登记号",
										type: "text",
										tips: "未报审时不用填写"
									},
									{
										key: "ordinary_record_num",
										title: "普通备案号",
										type: "text",
										tips: "未报审时不用填写"
									},
									{
										key: "key_record_num",
										title: "重点备案号",
										type: "text",
										tips: "未报审时不用填写"
									},
								],
							},

							{
								key: "record_material",
								title: "备案材料",
								type: "object",
								showRule: (formData) => {
									if (formData.album_info.qualification == 1) {
										return true;
									} else {
										return false;
									}
								},
								columns: [{
										key: "name",
										title: "剧名",
										type: "text",
									}, {
										key: "duration",
										title: "平均单集时长",
										type: "number",
										tips: "单位分钟，请填写整数"
									},
									{
										key: "seqs_count",
										title: "集数",
										type: "number",
									},
									{
										key: "production_organisation",
										title: "制作机构",
										type: "text",
										// tips: "未报审时不用填写"
									},
									{
										key: "director",
										title: "导演",
										type: "array<string>"
									},
									{
										key: "producer",
										title: "制作人",
										type: "array<string>"
									},
									{
										key: "actor",
										title: "演员",
										type: "array<string>",
										showRule: (formData) => {
											if (Object.keys(formData.record_material).length != 0) {
												let str = formData.record_material.actor[0] || ''
												if (str.includes(" ") || str.includes(".")) {
													const arr = str.split(/[\s.]+/); // 使用正则表达式匹配空格或句点
													const filteredArr = arr.filter(item => item !== '');
													formData.record_material.actor = filteredArr
												}
											}
											console.log("看看数据", formData);

										}
									},

									{
										"key": "summary",
										"title": "内容梗概",
										"type": "textarea",
										"placeholder": "1000 汉字以内",
										"autosize": {
											minRows: 4,
											maxRows: 10
										},
										"maxlength": 1000,
										"showWordLimit": true,
									},
									{
										"key": "cost_distribution_uri",
										title: "成本配置比例情况",
										type: "table-select",
										placeholder: "成本配置比例情况",
										queryColumns: [{
												key: "open_pic_id",
												title: "图片id",
												type: "text",
												width: 150,
												mode: "%%"
											},
											{
												key: "display_name",
												title: "名称",
												type: "text",
												width: 150,
												mode: "%%"
											}
										],
										tips: `<text>点此下载成本配置比例情况模板</text><a href="https://bytedance.larkoffice.com/file/OZADbVvvwoY2VXxV3oQcYKFLnjb" target="_blank">下载模板</a>`,
										"action": "admin/system_uni/uni-id-files/files/kh/getList",
										"columns": [{
												key: "open_pic_id",
												title: "封面id",
												type: "text",
												idKey: true,
												nameKey: true

											},
											{
												key: "url",
												title: "封面",
												type: "image",
											},
											{
												key: "display_name",
												title: "名称",
												type: "text",
											},
										],

										watch: (res) => {
											if (typeof res.option.open_pic_id === "undefined") {
												// 变量的值为 undefined
												vk.alert('该图片没有图片id，请重新选择');
												return
											}
											this.form1.data.record_audit_info.cost_distribution_uri = res
												.option.open_pic_id
											console.log("watch", res)
											console.log("成本配置比例情况:", this.form1.data.record_audit_info
												.cost_distribution_uri);
										}
									},
									{
										"key": "assurance_uri",
										title: "承诺书",
										type: "table-select",
										placeholder: "请选择承诺书",
										queryColumns: [{
												key: "open_pic_id",
												title: "图片id",
												type: "text",
												width: 150,
												mode: "%%"
											},
											{
												key: "display_name",
												title: "名称",
												type: "text",
												width: 150,
												mode: "%%"
											}
										],
										tips: `<text>点此下载承诺书模板</text><a href="https://bytedance.larkoffice.com/file/B56YbNcJEozdNWxOEMncYhEmnSe" target="_blank">下载模板</a>`,
										"action": "admin/system_uni/uni-id-files/files/kh/getList",
										"columns": [{
												key: "open_pic_id",
												title: "图片id",
												type: "text",
												idKey: true,
												nameKey: true

											},
											{
												key: "url",
												title: "图片",
												type: "image",
											}, {
												key: "display_name",
												title: "名称",
												type: "text",
											},
										],

										watch: (res) => {
											if (typeof res.option.open_pic_id === "undefined") {
												// 变量的值为 undefined
												vk.alert('该图片没有图片id，请重新选择');
												return
											}
											this.form1.data.record_audit_info.assurance_uri = res
												.option.open_pic_id
											console.log("watch", res)
											console.log("承诺书:", this.form1.data.record_audit_info
												.assurance_uri);
										}
									},
									{
										"key": "playlet_production_cost",
										"title": "制作成本类型",
										"type": "select",
										"data": [{
												value: 10,
												label: "30万以下"
											},
											{
												value: 20,
												label: "30～100万"
											},
											{
												value: 30,
												label: "100万以上"
											}
										],
										tips: "制作成本类型如选30万以下，视作已确认“我公司制作完成的微短剧总投资额不超过30万元，其中演员总片酬占比不超过40%”",

									},
									{
										key: "screen_writer",
										title: "编剧",
										type: "array<string>"
									},
								],
							},
							{
								key: "broadcast_record_info",
								title: "广电备案信息",
								tips: "没有广电备案号则不填",
								type: "object",
								showRule: (formData) => {
									if (formData.album_info.qualification == 1) {
										return true;
									} else {

										return false;
									}
								},
								columns: [{
										"key": "record_type",
										"title": "备案号类型",
										"type": "select",
										"data": [{
												value: 10,
												label: "普通备案号"
											},
											{
												value: 20,
												label: "重点备案号"
											}
										]

									},
									{
										key: "broadcast_record_number",
										title: "广电备案号",
										type: "text",
										tips: "无广电备案号时不用填写"
									},
								],
							},

						],
						// 表单验证规则
						rules: {
							ma_app_id: [{
								required: true,
								message: "appid必须填写",
								trigger: ['blur', 'change']
							}],
							album_info: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							title: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							seq_num: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							cover_list: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							year: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							album_status: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							recommendation: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							desp: [{
								required: true,
								message: "必填",
								trigger: ['blur', 'change']
							}],
							tag_list: [{
									required: true,
									message: "必填",
									trigger: ['blur', 'change']
								}

							],
							qualification: [{
									required: true,
									message: "必填",
									trigger: ['blur', 'change']
								},

							],
						},
						// add 代表添加 update 代表修改
						formType: "",
						// 是否显示表单的弹窗
						show: false
					}
				},
				// 其他弹窗表单
				formDatas: {},
				// 表单相关结束 -----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		async onReady() {

		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			console.log("oss=", vk.vuex.get('$app.ossinfo.region'));
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			async getSecUrl(tempUrl) {
				//如果数据库里没配置相关参数，则原样返回
				if (!this.baseurl) {
					return tempUrl;
				}
				let suffix = tempUrl.substr(-4); //截取后四位,如果后4位不是.mp4，说明已经获取过签名
				console.log("suffix=", suffix);
				if (suffix == ".mp4" || suffix == ".MP4") {
					//避免有些文件是http，因此统一替换成https
					tempUrl = tempUrl.replace('http://', 'https://');
					//清空域名信息，只留文件名信息，例如：anna/1.mp4
					let videoFile = tempUrl.replace(this.baseurl, '');
					//生成带签名的url
					let url = this.store.signatureUrl(videoFile, {
						expires: 3600, //3600秒到期
					});
					return url;
				} else {
					return tempUrl;
				}

			},
			async batchAdd(item) {
				console.log("看看数据", item);
				//如果已存在_id,就是编辑，否则就是新增（此处只能是已_id为判定条件）
				if (!this.form1.data.record_material.name || !this.form1.data.record_material.duration || !this
					.form1
					.data
					.record_material.seqs_count || !this.form1.data.record_material.production_organisation || !this
					.form1.data.record_material
					.producer[0] || !this
					.form1.data
					.record_material
					.actor[0] || !this
					.form1.data
					.record_material
					.summary || !this
					.form1.data
					.record_material
					.playlet_production_cost || !this
					.form1.data
					.record_material
					.director[0]) {

					vk.alert('短剧备案参数不完整，请检查必填项');
					return;
				}
				if (this.form1.data.broadcast_record_info.broadcast_record_number && !this.form1.data
					.broadcast_record_info.record_type) {
					vk.alert('请选择广电备案号类型');
					return;
				}
				//判断是否有广电备案
				item.album_info.record_audit_info = { //抖音备案审核信息
					record_material: item.record_material, //备案材料
					broadcast_record_info: item.broadcast_record_info //广电备案信息
				};

				//如果已存在_id,就是编辑，否则就是新增（此处只能是已_id为判定条件）
				if (item._id) {
					if (!this.form1.data.ma_app_id) {
						vk.alert('小程序appid参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.title) {
						vk.alert('短剧标题参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.seq_num) {
						vk.alert('总集数参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.cover_list[0]) {
						vk.alert('封面图列表参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.year) {
						vk.alert('发行年份参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.album_status) {
						vk.alert('短剧更新状态参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.recommendation || this.form1.data.album_info.recommendation
						.length > 12) {
						vk.alert('短剧推荐语未按要求填写');
						return;
					}

					if (!this.form1.data.album_info.desp || this.form1.data.album_info.recommendation.length >
						200) {
						vk.alert('短剧简介未按要求填写');
						return;
					}

					if (this.form1.data.album_info.tag_list.length == 0 || this.form1.data.album_info.tag_list
						.length >
						3) {
						vk.alert('短剧类目标签参数有误，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.qualification) {
						vk.alert('资质状态参数不完整，请检查必填项');
						return;
					}


					vk.callFunction({
						url: 'admin/pages/files_mzgl/dy_tv/kh/update',
						title: '请求中...',
						data: {
							_id: item._id,
							ma_app_id: item.ma_app_id,
							album_id: item.album_id, // 短剧id
							album_info: item.album_info,
							record_info: item.record_info, //原备案信息
							audit_status: item.audit_status, // 审核状态  默认 未送审
							status: item.status, // 创建状态
							// online_status:item.online_status,   // 上线状态
							_add_time: new Date().getTime(),
							_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
						},
						success: (data) => {
							this.form1.props.show = false; //关闭编辑窗口
							this.refresh()
						}
					});
					return;
				} else {
					if (!this.form1.data.ma_app_id) {
						vk.alert('小程序appid参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.title) {
						vk.alert('短剧标题参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.seq_num) {
						vk.alert('总集数参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.cover_list) {
						vk.alert('封面图列表参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.year) {
						vk.alert('发行年份参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.album_status) {
						vk.alert('短剧更新状态参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.recommendation || this.form1.data.album_info.recommendation
						.length > 12) {
						vk.alert('短剧推荐语未按要求填写');
						return;
					}

					if (!this.form1.data.album_info.desp) {
						vk.alert('短剧简介参数不完整，请检查必填项');
						return;
					}

					if (this.form1.data.album_info.tag_list.length == 0 || this.form1.data.album_info.tag_list
						.length >
						3) {
						vk.alert('短剧类目标签参数有误，请检查必填项');
						return;
					}

					if (!this.form1.data.album_info.qualification) {
						vk.alert('资质状态参数不完整，请检查必填项');
						return;
					}



					console.log('ma_app_id', item.ma_app_id);
					console.log('ma_app_id', item.album_info);
					let timenow = new Date().getTime();
					let addtv = await db.collection('dy_tv').add({
						ma_app_id: item.ma_app_id,
						album_id: item.album_id, // 短剧id
						album_info: item.album_info,
						record_info: item.record_info, //原备案信息
						audit_status: 1, // 审核状态  默认 未送审
						status: false, // 创建状态
						online_status: false, // 上线状态
						_add_time: timenow,
						_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
					})

					let all_series = item.album_info.seq_num;
					for (var i = 0; i < all_series; i++) {
						uni.showToast({
							title: i + "/" + all_series + "，请勿关闭浏览器...",
							icon: 'loading'
						})
						let seq = i + 1;
						let add = await db.collection('dy_tv_series').add({
							ma_app_id: item.ma_app_id,
							cover_list: [item.album_info.cover_list[0]],
							url: "http://" + item.album_info.title + "第" + seq +
								"集.mp4", // 必须有扩展名 才能同步到控制台 （大概两分钟控制台会显示）
							title: item.album_info.title + "-第" + seq + "集", //  此内容不会覆盖抖音云原本的内容
							format: "mp4",
							use_dy_cloud: true,
							dy_cloud_id: "", //vid默认为0,需用户自填
							open_video_id: "", //pid默认为0,抖音开放平台视频id,需用户填写vid上传获取
							episode_id: "", //剧集id
							seq: seq,
							status: false, // 上传状态
							tv_id: addtv.result.id,
							_add_time: timenow,
							_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
						})
					}
					this.form1.props.show = false; //关闭编辑窗口
					vk.alert('恭喜！添加完成');
					this.refresh()
				}
			},
			copylink() {
				let that = this;
				uni.downloadFile({
					url: this.currentlink,
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {}
				});
				uni.setClipboardData({
					data: this.currentlink,
					success() {
						// vk.toast('复制成功', 'none');
						that.$message({
							message: '视频链接复制成功：' + that.currentlink,
							type: 'success'
						});
					}
				})
			},
			//点按钮换集
			async cut_serie(item) {

				this.currentlink = item.video_src
				this.currentserie = item.series

			},
			//弹窗关闭前做一下判断或操作
			handleClose() {
				this.dialogVisible = false;
			},
			// 页面数据初始化函数
			init(options) {
				originalForms["form1"] = vk.pubfn.copyObject(that.form1);
			},
			// 页面跳转
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 表单重置
			resetForm() {
				vk.pubfn.resetForm(originalForms, that);
			},
			// 搜索
			search() {
				that.$refs.table1.search();
			},
			// 刷新
			refresh() {
				that.$refs.table1.refresh();
			},
			// 获取当前选中的行的数据
			getCurrentRow() {
				return that.$refs.table1.getCurrentRow();
			},
			// 监听 - 行的选中高亮事件
			currentChange(val) {
				that.table1.selectItem = val;
			},
			// 当选择项发生变化时会触发该事件
			selectionChange(list) {
				that.table1.multipleSelection = list;
			},
			// 显示添加页面
			addBtn() {
				that.resetForm();
				that.form1.props.action = 'admin/pages/kh/dsjzxgl/dsj/add';
				that.form1.props.formType = 'add';
				that.form1.props.title = '添加';
				that.form1.props.show = true;
			},
			// 显示修改页面
			updateBtn({
				item
			}) {
				//初始化备案数据
				if (item.album_info.qualification == 1) {
					if (item.album_info.record_audit_info) {
						console.log('111111111111111111111111');
						item.broadcast_record_info = item.album_info.record_audit_info
							.broadcast_record_info || {}
						item.record_material = item.album_info.record_audit_info
							.record_material || {
								actor: [],
								producer: [],
								director: [],
								screen_writer: []
							}
					}
				}
				that.form1.props.action = 'admin/pages/kh/dsjzxgl/dsj/update';
				that.form1.props.formType = 'update';
				that.form1.props.title = '编辑';
				that.form1.props.show = true;
				that.form1.data = item;
			},
			// 删除按钮
			deleteBtn({
				item,
				deleteFn
			}) {
				deleteFn({
					action: "admin/pages/files_mzgl/dy_tv/kh/delete",
					data: {
						_id: item._id
					},
				});
			},

		},
		// 监听属性
		watch: {

		},
		// 过滤器
		filters: {

		},
		// 计算属性
		computed: {

		}
	};
</script>
<style lang="scss" scoped>
	.page-body {}

	// 滚动条样式
	/deep/ ::-webkit-scrollbar {
		/*滚动条整体样式*/
		width: 4px !important;
		height: 1px !important;
		overflow: auto !important;
		background: #ccc !important;
		-webkit-appearance: auto !important;
		display: block;
	}

	/deep/ ::-webkit-scrollbar-thumb {
		/*滚动条里面小方块*/
		border-radius: 10px !important;
		box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
		background: #7b7979 !important;
	}

	/deep/ ::-webkit-scrollbar-track {
		/*滚动条里面轨道*/
		// box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
		// border-radius: 10px !important;
		background: #FFFFFF !important;
	}
</style>